package com.oig.sys.msg.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import java.io.Serializable;


/**
 * @author wuxl
 * 1、主动发送消息方，插入一条待发消息到发送表 2、轮询消息表的服务，轮询待发消息，根据应用id+主单据类型+关联单据查询配置表，找到对应的消息发送连接，发送消息，  连接是程序启动是根据配置自动启动 
 */
@Getter
@Setter
@ToString
@Entity
@Table(name = "tb_mq_msg_his")
@EntityListeners({AuditingEntityListener.class})
public class TbMqMsgHis implements Serializable {

	/**
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	private Integer id;

	@Column(name = "mq_id")
	private Integer mqId;
	/**
	 * 应用id
	 */
	@Column(name = "system_id")
	private Integer systemId;

	/**
	 * 应用名称
	 */
	@Column(name = "system_name")
	private String systemName;

	/**
	 * 主单据类型
	 */
	@Column(name = "business_type")
	private String businessType;

	/**
	 * 关联单据
	 */
	@Column(name = "relation_type")
	private String relationType;

	/**
	 * 关联单号
	 */
	@Column(name = "relation_id")
	private String relationId;

	/**
	 * 要发出去的消息内容 json格式
	 */
	@Column(name = "msg_content")
	private String msgContent;

	/**
	 * 消息创建时间
	 */
	@CreatedDate
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time")
	private java.util.Date createTime;

	/**
	 * 发送状态 0-待发 1-已发 默认查待发的消息
	 */
	@Column(name = "send_flag")
	private String sendFlag;

	/**
	 * 发送次数 主要是允许已发送的消息可以再次手工点击发送
	 */
	@Column(name = "send_num")
	private Integer sendNum;

	/**
	 * 最后发送时间
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "send_time")
	private java.util.Date sendTime;

	/**
	 * 版本号
	 */
	@Version
	@Column(name = "version")
	private Integer version;

	/**
	 * 所属租户id  跟着单据来
	 */
	@Column(name = "tenant_id")
	private Integer tenantId;

	/**
	 * 所属租户名称
	 */
	@Column(name = "tenant_name")
	private String tenantName;


	@Column(name = "error_flag")
	private String errorFlag;
}
